package org.itzheng.itplayer.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.itzheng.base.BaseFragment
import org.itzheng.itplayer.R
import org.itzheng.itplayer.adapter.MainMenuAdapter
import org.itzheng.itplayer.data.DataMainMenu
import org.itzheng.setGridAdapter
import org.itzheng.setLinearAdapter

/**
 * Title:<br></br>
 * Description: <br></br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2020-12-2.
 */
class MainFragment : BaseFragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflate(R.layout.fragment_main)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setAdapter()
    }

    var adapter: MainMenuAdapter? = null
    private fun setAdapter() {
        if (adapter == null) {
            adapter = MainMenuAdapter()
            rootView.findViewById<RecyclerView>(R.id.rcvContent).setGridAdapter(adapter!!, 2)
            adapter?.submitList(DataMainMenu.getMainMenus(mainActivity))
        }
    }

    companion object {
        fun newInstance(): MainFragment {
            val args = Bundle()
            val fragment = MainFragment()
            fragment.arguments = args
            return fragment
        }
    }
}